<%@include file="/WEB-INF/views/includes/taglibs.jsp"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@include file="/WEB-INF/views/includes/adminHeader.jsp"%>



<!--[if gte IE 6]>
<script>
$(document).ready( function() {
$(".dataRow").mouseover(function(){$(this).addClass("dataRowOver");});
$(".dataRow").mouseout(function(){$(this).removeClass("dataRowOver");});
});
</script>
<![endif]-->
<script type="text/javascript">
function disableFunction(id, functionId, name) {
	$("#disableId").val(id);
	$("#isenable").val("false");
	$("#disableFunctionId").text(functionId);
	$("#disableFunctionName").text(name);
	$("#disablemessage").text("Confirm to disable?");
	$('#disableDialog').dialog('open');
}

function enableFunction(id, functionId, name) {
	$("#disableId").val(id);
	$("#isenable").val("true");
	$("#disableFunctionId").text(functionId);
	$("#disableFunctionName").text(name);
	$("#disablemessage").text("Confirm to enable?");
	$('#disableDialog').dialog('open');
}

function editFunction(id) {
	window.location.href = "<c:url value='/web/editFunction?id='/>" + id;
}

$(document).ready(
		function() {
			$('#disableDialog').dialog({
				autoOpen: false,
				width: 400,
				draggable : true,
				resizable : false,
				dialogClass : 'disableDialog',
				buttons: {
					"Yes, I'm sure": function() {
						var idToBedisabled = $("#disableId").val();
						var isenable = $("#isenable").val();
						window.location.href = "<c:url value='/web/disableFunction?id='/>" + idToBedisabled + "&isenable=" + isenable;
					},
					"No, I don't want": function() {
						$(this).dialog("close");
					}
				}
			});
		});
</script>
<div id="disableDialog" title="Disable/Enable Function">
	<h3 id="disablemessage">Confirm to disable? </h3>
	<input type="hidden" id="disableId" name="disableId"/>
	<input type="hidden" id="isenable" name="isenable"/>
	<div><span class="label">Function ID:</span><span id="disableFunctionId"></span></div>
	<div><span class="label">Function Name:</span><span id="disableFunctionName"></span></div>
	<br/>
</div>


<div class="homePage ui-tabs-panel ui-widget-content ui-corner-bottom">
	<div id="leftMenu">
		<%@include file="/WEB-INF/views/includes/functionAdminLeftNav.jsp"%>
	</div>
	<div id="rightContent">
		<%@include file="/WEB-INF/views/includes/messages.jsp"%>
		<h2>Function List</h2>
		<div class="searchBlock">
				<form:form method="post" action="functionHome" id="searchFunctionform">
					<form:label path="functionID">Function ID</form:label>&nbsp;<form:input path="functionID"/>&nbsp;&nbsp;
					<form:label path="functionName">Function Name</form:label>&nbsp;
					<form:input path="functionName"/>&nbsp;&nbsp;
					<form:label path="typeId">Function Type</form:label>&nbsp;
					<form:select path="typeId">
							<form:option value="0" label="All" />
							<form:options items="${functionTypes}"  itemValue="id" itemLabel="name" />
					</form:select>&nbsp;&nbsp;
					<br/>
					<button type="button"
						class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
						onclick="save()" style="margin-top:5px">
						<span class="ui-button-text">Search Function</span>
					</button>
					<script type="text/javascript">
						function save() {
							$('#searchFunctionform').submit();
						}
					</script>
				</form:form>
		</div>
		<div>
			<table class="generaltable" style="width:100%" cellspacing="0" cellpadding="0">
				<thead>
					<tr>
						<th>Function ID</th>
						<th>Function Name</th>
						<th>Function Type</th>
						<th>Function Status</th>
						<th>Function Provider</th>
						<th>Provider Connector configure</th>
						<th>Operations</th>
					</tr>
				</thead>
				<tbody>
				<c:if test="${not empty functionList}">
					<c:forEach items="${functionList}" var="oneFunction">
					<tr class="dataRow">
						<td>${oneFunction.functionID}</td>
						<td>${oneFunction.functionName}</td>
						<td>${oneFunction.functionType}</td>
						<td>${oneFunction.statusValue}</td>
						<td>${oneFunction.bizsysName}</td>
						<td>${oneFunction.connectorConfigName}</td>
						<td><a href="#" onclick="editFunction('${oneFunction.functionID}')">Edit</a>&nbsp;&nbsp;
						<c:if test="${oneFunction.status == 1}">
						<a href="#" onclick="disableFunction(${oneFunction.id}, '${oneFunction.functionID}', '${oneFunction.functionName}')">disable</a>
						</c:if>
						<c:if test="${oneFunction.status != 1}">
						<a href="#" onclick="enableFunction(${oneFunction.id}, '${oneFunction.functionID}', '${oneFunction.functionName}')">enable</a>
						</c:if>
						<a href="<c:url value='/web/functionPrameter?functionId='/>${oneFunction.functionID}">Edit Parameters</a>
						
						</td>
					</tr>
					</c:forEach>
				</c:if>
				</tbody>
			</table>
		</div>
		<div style="height:1px;width:740px;"></div>
	</div>
</div>

<%@include file="/WEB-INF/views/includes/adminfooter.jsp"%>